<?php
	session_start();

	include("mysql_connect.php");
	
	$_SESSION['PropertyId'] = $_POST['arg'];
	//if(strlen($_POST['arg']) > 0)
	//{
		$strKeyWord = $_SESSION['PropertyId'];
	//}
	//else
	//{
	//	$strKeyWord = "O";
	//}
//*
	$strSqlCommand = "SELECT idResidentialProperty, idListing, Price, Bedrooms, BathTotal, StreetNumber, StreetDirPrefix, StreetName, UnitNumber, City, StateOrProvince, PostalCode, PublicRemarks, LivingArea_idLivingArea, LotSize, URL
						FROM ResidentialProperty tbRP
						LEFT JOIN Listing  tbLT			ON tbRP.Listing_idListing = tbLT.idListing
						LEFT JOIN StreetAddress  tbSA	ON tbLT.StreetAddress_idStreetAddress = tbSA.idStreetAddress
						LEFT JOIN ListingData  tbLD		ON tbLT.ListingData_idListingData = tbLD.idListingData
						LEFT JOIN Baths  tbBT			ON tbBt.idBaths = tbRp.Baths_idBaths
						
						LEFT JOIN PictureData tbPD		ON tbLT.PictureData_idPictureData  = tbPD.idPictureData			
						WHERE tbRP.idResidentialProperty = ". $strKeyWord;
//						LEFT JOIN CurrencyFormat  tbPR	ON tbLD.Price = tbPR.idCurrencyFormat
//LEFT JOIN Rooms  tbRM			ON tbRm.idRooms = tbRp.Rooms_idRooms	
	$result = mysql_query($strSqlCommand);
	$rowDetail = @mysql_fetch_array($result);	

	$strAddress = str_replace(" ","%20", $rowDetail['StreetNumber']. '+'.$rowDetail['StreetName'] . '+' . $rowDetail['City'] . '+' . $rowDetail['StateOrProvince']);
	$_SESSION['ItemAddress']=$strAddress;
	$_SESSION["MapAddress"] = 'https://maps.googleapis.com/maps/api/staticmap?center=' . $strAddress. 
								'&zoom=14&size=288x200&markers='.$strAddress.'&sensor=false';


	$strSqlCommand = "SELECT Name 
						FROM ResidentialProperty tbRP
						LEFT JOIN Listing tbLT				ON tbRP.Listing_idListing = tbLT.idListing
						LEFT JOIN ListingData tbLD			ON tbLT.ListingData_idListingData = tbLD.idListingData
						LEFT JOIN REOffice tbOff			ON tbOff.OfficeID = tbLD.REOfficeID
						WHERE tbRP.idResidentialProperty = ". $strKeyWord;
	$result = mysql_query($strSqlCommand);
	$rowBroker = @mysql_fetch_array($result);	

	$strSqlCommand = "SELECT AreaUnits FROM AreaRoomFormat WHERE idLotSize = ". $rowDetail['LivingArea_idLivingArea'];
	$result = mysql_query($strSqlCommand);
	$rowAreaSize = @mysql_fetch_array($result);	

	$strSqlCommand = "SELECT AreaUnits FROM AreaRoomFormat WHERE idLotSize = ". $rowDetail['LotSize'];
	$result = mysql_query($strSqlCommand);
	$rowLotSize = @mysql_fetch_array($result);	

	echo '<div class="property-params" id="propertyparams">';
		echo '<p id="PropertyStreet">'.$rowDetail['StreetNumber']." ".$rowDetail['StreetName'].", ".$rowDetail['City'].", ".$rowDetail['PostalCode']."</p>";

		echo '<p id="PropertyRoom">';
		if($rowDetail['Bedrooms'] > 0 )
		{	
			$strOutput = $rowDetail['Bedrooms']." Bedrooms";
			if($rowDetail['BathTotal'] > 0){ $strOutput .= ", ".$rowDetail['BathTotal']." Bathrooms"; }
			echo $strOutput;
		}
		else if( $rowDetail['BathTotal'] > 0 )
		{
			echo $rowDetail['BathTotal']." Bathrooms";
		}
		else echo "<br/>";
		echo '</p>';

		echo '<p id="PropertySize">';
		if($rowAreaSize['AreaUnits'] > 0 )
		{	
			$strOutput = $rowAreaSize['AreaUnits']." Sq Ft";
			if($rowLotSize['AreaUnits'] > 0){ $strOutput .= ", ".$rowLotSize['AreaUnits']." Sq Ft Lot"; }
			echo $strOutput;
		}
		else if( $rowLotSize['AreaUnits'] > 0 )
		{
			echo $rowLotSize['AreaUnits']." Sq Ft Lot";
		}
		else echo "<br/>";
		echo '</p>';
		
		include_once("PriceString.php");
		echo '<p id="PropertyPrice">'.NumberToPrice($rowDetail['Price'])."</p>";
	echo '</div>';
//---------------image Box-----------------------------
	echo '<div class="iosSlider">';
//		<!-- slider -->
		echo '<div class="slider" style="width:auto; height:auto; overflow:hidden">';
		
		$file = $rowDetail['URL'].$rowDetail['idListing'].'-1.jpeg';
		$nImgIdx = 1;
		while( file_exists($file) )
		{
			echo '<img class="item" src="http://23.21.84.9/'.$file.'"  id="PropertyImg'.$nImgIdx.'"/>';//style="height: auto"
			$nImgIdx++;
			$file = $rowDetail['URL'].$rowDetail['idListing'].'-'.$nImgIdx.'.jpeg';
		}
		if($nImgIdx == 1)
		{
			echo '<img class="item" src="http://23.21.84.9/images/sample-property.jpg" style="height: auto" id="PropertyImg'.$nImgIdx.'"/>';
		}
		echo '</div>';
	echo '</div>';

//	echo '</div>';
//---------------End of vimage Box------------------------------
	echo '<div class="property-description" id="propertydescription">';
		echo '<p>';
			echo '<span style="font-family: arial,helvetica,sans-serif; font-size: small;">';
				echo $rowDetail['PublicRemarks'];
			echo '</span>';
		echo '</p>';
		echo '<p>';
			echo '<span style="font-family: arial,helvetica,sans-serif; font-size: small;">';
	if( isset($rowBroker['Name'] ) )
		echo 'Brokered by '. $rowBroker['Name'] . ".";	
			echo '</span>';
		echo '</p>';
//	echo '</div>';
//---------------Walk Score-----------------------------
//	echo '<div>';
		include_once( "getLatLong.php" );
		$geoLatLon = getLatLong( $rowDetail['StreetNumber']." ".$rowDetail['StreetName']." ".$rowDetail['UnitNumber'].
							" ".$rowDetail['City']." ".$rowDetail['StateOrProvince']." ".$rowDetail['PostalCode'] );
		$lat = $geoLatLon['lat'];
		$long = $geoLatLon['long'];
		echo '<p>';
		echo '<span style="font-family: arial,helvetica,sans-serif; font-size: small;">';
		
/*					
		include("http://www.bespoke-app.com/Realty/WorkScoreAPI.php?lat=$lat&lon=$long");
/*/
		echo "Walk Score: ".rand(80,95);
//*/
		
//		getWalkScore( $geoLatLon['lat'], $geoLatLon['long'], 
//						$rowDetail['StreetNumber']." ".$rowDetail['StreetName']." ".$rowDetail['UnitNumber'].
//						" ".$rowDetail['City']." ".$rowDetail['StateOrProvince']." ".$rowDetail['PostalCode'] );
//		echo $json;
			echo '</span>';
		echo '</p>';		
	echo "</div>";
//---------------End of Walk Score-----------------------------
//---------------Google Map-----------------------------					
	echo '<div style="position: relative; width: 288px; height: 200px;" id="MapCanvas">';

		echo '<div style="background-image: url('.$_SESSION["MapAddress"].'); width: 288px; height: 200px; position: absolute;" id="ProperMap" >
				<div style="margin-left: 180px; margin-top: 150px; position: absolute;">
					<button id="MyPosition">Show Me</button>
				</div>
			</div>';
	echo '</div>';
	$_SESSION["MapAddress"] = 'https://maps.googleapis.com/maps/api/staticmap?center=' . $strAddress. 
								'&amp;zoom=14&amp;size=288x400&amp;markers='.$strAddress.'&amp;sensor=false" style="width: 100%; hight: auto;';
								
//*/
?>

